package 常用API;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
工具类
    构造方法私有
    成员方法静态
 */
public class DateUtils {
    private DateUtils(){}

    //日期转字符串
    //返回值string
    //参数 Date date，String format
    public static String DateToString(Date date,String format){
        SimpleDateFormat sdf=new SimpleDateFormat(format);
        String s = sdf.format(date);
        return s;
    }

    //字符串解析日期
    //返回值Date
    //参数：String s,Sting format
    public static Date StringToDate(String s,String format) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat(format);
        Date d = sdf.parse(s);
        return d;
    }
}
